﻿namespace MefContrib.Models.Provider.Tests
{
    using System;
    using System.Collections.Generic;
    using NUnit.Framework;
    using MefContrib.Models.Provider.Validation;

    [TestFixture]
    public class ProviderExportDefinitionTests
    {
        [Test, ExpectedException(typeof(ArgumentNullException))]
        public void ConstructorShouldThrowExceptionIfMemberParameterIsNull()
        {
            ProviderExportDefinition export =
                new ProviderExportDefinition(null, null);
        }

        [Test, ExpectedException(typeof(ArgumentNullException))]
        public void ConstructorShouldThrowExceptionIfExportDescriptionIsNull()
        {
            ProviderExportDefinition export =
                new ProviderExportDefinition(typeof(ProviderExportDefinitionTests), null);
        }

        [Test]
        public void ConstructorShouldNotThrowExceptionIfContractNameAndContractTypeAreEmpty()
        {
            var description = new ExportDescription();
            ProviderExportDefinition export =
                new ProviderExportDefinition(typeof(ProviderExportDefinitionTests), description);

            Assert.That(export.ContractName, Is.EqualTo("MefContrib.Models.Provider.Tests.ProviderExportDefinitionTests"));
        }

        [Test]
        public void ContractNameShouldReturnValuePassedInConstructor()
        {
            var description = new ExportDescription { ContractName = "contract" };
            var export = new ProviderExportDefinition(typeof(ProviderExportDefinitionTests), description);

            Assert.AreEqual(export.ContractName, "contract");
        }

        [Test]
        public void MetadataShouldNotBeNullWhenPassedInConstructor()
        {
            var metadata = new Dictionary<string, object> { { "Foo", 0 }, { "Bar", 1 } };
            var description = new ExportDescription { ContractName = "contract", Metadata = metadata };
            var export = new ProviderExportDefinition(typeof(ProviderExportDefinitionTests), description);

            Assert.IsNotNull(export.Metadata);
        }

        [Test]
        public void MemberShouldReturnValuePassedInConstructor()
        {
            var member = typeof(ProviderExportDefinitionTests);
            var description = new ExportDescription { ContractName = "contract" };
            var export = new ProviderExportDefinition(typeof(ProviderExportDefinitionTests), description);

            Assert.AreEqual(export.Member, member);
        }
    }
}